import uniRequest from 'uni-request';
import store from './index.js';
import { showLoading, hideLoading } from './load.js'
// uniRequest.defaults.headers.post['Content-Type'] = 'text/html; charset=UTF-8'
uniRequest.defaults.baseURL = "http://www.jdycs.com:82/index.php/api/";

// uniRequest.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
 // uniRequest.defaults.headers("Access-Control-Allow-Origin", "*")
uniRequest.interceptors.request.use(
	config => {
		showLoading();
		let token
		uni.getStorage({key: 'user',success(res) {
				token = res.data.token
				console.log(token)
			}
		})
		// config.headers.authorization = token
		
			// let token = store.state.userInfo.token
			  config.headers['token'] = store.state.userInfo.token
		
		return config;
	},
	error => {
		return Promise.reject(error);
	});
	
	
	// 响应拦截
	uniRequest.interceptors.response.use(function(response) {
		hideLoading()
		// if (response.data.code == 0) {
		// 	uni.showToast({
		// 		title: '',
		// 		icon: 'none',
		// 		success() {
		// 			uni.reLaunch({
		// 				// url: '/pages/login/login'
		// 			})
		// 			return
		// 		}
		// 	});
		// }
		return response;
	}, function(err) {
		return Promise.reject(err);
	});
	
	export default uniRequest